1<!DOCTYPE html>
<html >
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>创建调查预览页</title>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/base.css"/>
		<link rel="stylesheet" type="text/css" href="../../css/study.css" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<style type="text/css" media="screen">
			.next_btn {
				width: 92%;
				height: 67%;
				font-size: 16px;
				background: url(../../icon/add_research.png) no-repeat 36% 50%;
				background-size: 20px 20px;
				background-color: #18b4ed;
			}
			.mui-btn-warning, .mui-btn-yellow {
				color: #fff;
				border: 1px solid #18b4ed;
			}
			.mui-btn-warning:enabled:active {
				color: #fff;
				border: 1px solid #18b4ed;
				background-color: #18b4ed;
			}
			.nav-item:active {
				color: #fff;
			}
		</style>
	</head>
	<body class="">
		<div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
		<div class="base_navigation_bar base_style_color base_navigation_item_bar">
			<a class="base_left_item nav-item" href="#" onclick="backToast()"> 取消 </a>
			<span id="title">编辑调查</span>
			<a class="base_right_item nav-item" href="#" onclick="submit()"> 保存 </a>
		</div>
		<div id="offlineAlert" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title" id="checkNum">是否放弃当前问题编辑页面？</strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
					<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
		<div id="showAlert" class="weui_dialog_confirm" style="display: none;">
			<div class="weui_mask"></div>
			<div class="weui_dialog">
				<div class="weui_dialog_hd">
					<strong class="weui_dialog_title">是否确定开启此调查？</strong>
				</div>
				<div class="weui_dialog_bd"></div>
				<div class="weui_dialog_ft">
					<a  href="#" class="weui_btn_dialog default" id="openSign_no" style="color:#18b4ed">取消</a>
					<a  href="#" class="weui_btn_dialog primary" id="openSign_yes" style="color:#18b4ed">确定</a>
				</div>
			</div>
		</div>
		<div id="bottom_bar" class="course_select_footer "style="padding-top: 6px;padding-bottom: 6px">
			<button id="sumbit_bt" type="button" class="mui-btn-warning horcenter next_btn " onclick="addQuestion()">
				添加问题
			</button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript">
		var questionArr2 = new Array();
		var questionArr = new Array();
		var questionArr3 = '';
		var className = '';
		var classid = '';
		var name = '';
		var classarr = new Array();
		var daan = new Object();
		var ResearchName = '';
		var Research_className = '';
		var Research_classid = '';
		var Research_submit_toast = '';
		apiready = function() {
			if (api.pageParam.type1 == 5) {//编辑题目时
				deleteStorage();
				$api.setStorage('ResearchName2', api.pageParam.name);
				$api.setStorage('UpdateId2', api.pageParam.id);
				setupSubframe2(api.pageParam.type1);
			} else if (api.pageParam.type1 == 11 || api.pageParam.type1 == 12) {
				classarr = api.pageParam.classarr;
				setupSubframe2(api.pageParam.type1);
			} else if (api.pageParam.type1 == 7) {
				classarr = api.pageParam.classarr;
				setupSubframe2(api.pageParam.type1);
			}
			$('#title').text('编辑' + ludongJudge());
			ReceNotifi();
			ludongJudge();
			btnClick();
		};
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}

		//按钮点击事件
		function btnClick() {
			$('#openSign_no').click(function() {
				$('#showAlert').hide();
				returnList()
			});
			//正常情况下是否退出当前考试按钮确定键
			$('#openSign_yes').click(function() {
				$('#showAlert').hide();
				start()
			});
		}

		//是否是鲁东智慧课堂
		function ludongJudge() {
			//读取消息推送
			var jid = $api.getStorage('cfnetppjxid');
			if (jid != 425) {//非鲁东智能课堂
				return '调查'
			} else {
				return '投票'
			}
		}

		function deleteStorage() {
			$api.setStorage('Research_className2', '');
			$api.setStorage('Research_classid2', '');
			$api.setStorage('ResearchName2', '');
			$api.setStorage('Research_submit_toast2', '');
		}

		//退出提示
		function backToast() {
			if ($api.getStorage('ResearchName2') == '' && $api.getStorage('Research_className2') == '' && ($api.getStorage('Research_submit_toast2') == '' || $api.getStorage('Research_submit_toast2') == undefined)) {
				returnList();
			} else {
				$('#offlineAlert').show();
				api.setFrameAttr({
					name : 'Teacher_EditResearchListDetail',
					hidden : true
				});
			}
		}

		//确定
		function cleanConfirm() {
			$('#offlineAlert').hide();
			returnList();
		}

		//取消
		function cleanCancel() {
			$('#offlineAlert').hide();
			api.setFrameAttr({
				name : 'Teacher_EditResearchListDetail',
				hidden : false
			});
		}

		function backClick() {
			api.closeWin();
		}

		//开始活动
		function start() {
			var params = {
				tid : 3,
				iid : $api.getStorage('UpdateId2'),
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				action : "start",
			}
			cfnetppPOST(url_actionDosign, params, false, function(data, status) {
			SendBusinessOperationsLogNotifi('老师端调查开始', '197', params, params, '', data, '老师端调查开始接口', '197-01')
				api.hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						openResearch($api.getStorage('UpdateId2'))
					} else {
						ShowToast('开启失败');
						api.setFrameAttr({
							name : 'Teacher_EditResearchListDetail',
							hidden : false
						});
					}
				} else {
					ShowToast('开启失败');
					api.setFrameAttr({
						name : 'Teacher_EditResearchListDetail',
						hidden : false
					});
				}
			})
		}

		//打开调查详情页
		function openResearch(id) {
			api.openWin({useWKWebView:true,
				name : 'Teacher_ResearchListDetail',
				url : 'Teacher_ResearchListDetail.html',
				pageParam : {
					id : id,
					name : $api.getStorage('ResearchName'),
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
					sourceurl : api.pageParam.sourceurl,
					sourcetitle : api.pageParam.sourcetitle
				},
			});
		}

		//接收通知
		function ReceNotifi() {
			api.addEventListener({
				name : 'deleteQuestionNotifi'
			}, function(ret, err) {
				questionArr2 = ret.value.data;
				daan.questionitems = ret.value.data;
				classarr = ret.value.classarr;
			});
			api.addEventListener({
				name : 'keyback'
			}, function(ret, err) {
				//coding...
				backToast();
			});
			api.addEventListener({
				name : 'getDataNotifi'
			}, function(ret, err) {
				//coding...
				questionArr2 = ret.value.data;
				if (api.systemType == 'ios') {
					daan.questionitems = ret.value.data;
				}
			});
		}

		//编辑时,打开列表
		function setupSubframe2(type1) {
			var pageParam = '';
			if ( type1 = 11 || type1 == 12) {
				pageParam = {
					id : $api.getStorage('UpdateId2'),
					name : $api.getStorage('ResearchName2'),
					classname : $api.getStorage('Research_className2'),
					type1 : api.pageParam.type1,
					data : api.pageParam.data,
					classarr : api.pageParam.classarr,
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
				};
			} else {
				pageParam = {
					id : $api.getStorage('UpdateId2'),
					name : $api.getStorage('ResearchName2'),
					type1 : type1,
				};
			}
			var y = $('.base_navigation_bar').height() + 22;
			var h = api.winHeight - y - 54;
			api.pageParam['sourceurl'] = api.pageParam.sourceurl;
			api.pageParam['sourcetitle'] = api.pageParam.sourcetitle;
			api.openFrame({
				name : 'Teacher_EditResearchListDetail',
				url : 'Teacher_EditResearchListDetail.html',
				rect : {
					x : 0,
					y : y,
					w : 'auto',
					h : h
				},
				pageParam : pageParam,
				reload : true
			});
		}

		//添加问题
		function addQuestion() {
			ResearchName = $api.getStorage('ResearchName2');
			Research_className = $api.getStorage('Research_className2');
			if (isEmpty(ResearchName)) {
				ShowToast('请填写' + ludongJudge() + '名称');
				return false
			}
			api.openWin({useWKWebView:true,
				name : 'Teacher_AddResearchQuestion',
				url : 'Teacher_AddResearchQuestion.html',
				pageParam : {
					data : questionArr2,
					type : 10,
					classarr : classarr,
					pid : api.pageParam.pid,
					cid : api.pageParam.cid,
					sourceurl : api.pageParam.sourceurl,
					sourcetitle : api.pageParam.sourcetitle
				},
				slidBackEnabled : false,
				reload : true
			});
		}

		//完成按钮点击触发事件
		function submit() {
			ResearchName = $api.getStorage('ResearchName2');
			Research_className = $api.getStorage('Research_className2');
			Research_classid = $api.getStorage('Research_classid2');
			Research_submit_toast = $api.getStorage('Research_submit_toast2');
			if (ResearchName == '' || isOnlySpaceOrEnter(ResearchName)) {
				ShowToast('请填写' + ludongJudge() + '名称');
				return false
			}
			if (daan.questionitems == '' || daan.questionitems == undefined) {
				ShowToast('请添加问题');
				return false
			}
			UpdataData();
		}

		//更新数据
		function UpdataData() {
			var param = {
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
				id : $api.getStorage('UpdateId2'),
				pid : api.pageParam.pid,
				cid : api.pageParam.cid,
				name : $api.getStorage('ResearchName2'),
				question : daan,
				content : $api.getStorage('Research_submit_toast2'),
				classid : '',
			};
			cfnetppPOST(url_EditActive, param, true, function(data, status) {
				SendBusinessOperationsLogNotifi('老师端调查编辑', '198', param, param, '', data, '学生提交调查接口', '198-01')
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						ShowToast('更新成功');
						$('#showAlert').show();
						api.setFrameAttr({
							name : 'Teacher_EditResearchListDetail',
							hidden : true
						});
						sendNotifi();
					} else if (data.code == 110) {
						ShowToast(ludongJudge() + '名称已存在');
					} else {
						ShowToast(data.message);
					}
				} else {
					api.toast({
						msg : '网络异常',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}

		//发送通知
		function sendNotifi() {
			api.sendEvent({
				name : 'RerfeshThList'
			});
		}

		//返回列表页
		function returnList() {
			sendBuriedNotifi('1', '老师端调查编辑页', '198');
			api.closeToWin({
				name : 'Teacher_ResearchWindow'
			});
		}
	</script>
</html>
